package com.woniu.job.controller;


import com.woniu.job.entity.Company;
import com.woniu.job.entity.Interview;
import com.woniu.job.entity.PageBean;
import com.woniu.job.entity.Resumework;
import com.woniu.job.entity.vo.InterviewVO;
import com.woniu.job.entity.vo.ResponseVO;
import com.woniu.job.service.IInterviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("interview")
public class InterviewController {
    @Autowired
    private IInterviewService interviewService;

    /**
     * 添加面试邀请
     * @param interviewVO
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public ResponseVO add(@RequestBody InterviewVO interviewVO){
        if (interviewVO.getResumeIds()!=null && interviewVO.getResumeIds().size()!=0 && interviewVO.getTime()!=null
        && interviewVO.getTime()!="" && interviewVO.getAddress()!=null && interviewVO.getAddress()!=""){
            String time = interviewVO.getTime().replace("T"," ");
            interviewVO.setTime(time);
            interviewService.add(interviewVO);
        }
        return new ResponseVO("200","suc",null);
    }

    /**
     * 添加个人面试邀请
     * @param interview
     * @return
     */
    @PostMapping("addone")
    @ResponseBody
    public ResponseVO addOne(@RequestBody Interview interview,@SessionAttribute Company company){
        interview.setCompanyId(company.getId());
        interviewService.addOne(interview);
        return new ResponseVO("200","suc",null);
    }
    /**
     * 面试列表页
     * @param
     * @return
     */
    @GetMapping("list/{page}")
    public String add(Model model, @SessionAttribute(required = false) Company company, @PathVariable Integer page){
        if (page==null || page==0){
            page=1;
        }
        if (company!=null){
            PageBean<Interview> interviewPageBean =  interviewService.list(company.getId(),page);
            model.addAttribute("interview",interviewPageBean);
        }
        return "company/interviews";
    }
}
